Clover coverage report - Enterprise Web Services - 1.0
Coverage timestamp: Mon May 30 2005 17:10:32 CEST
file stats: LOC: 339   Methods: 27
NCLOC: 278   Classes: 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
 
 Source file Conditionals Statements Methods TOTAL
Utils.java 12.5% 27.9% 37% 23.6%
coverage coverage
 1   
 /*
 2   
  * Copyright 2001-2004 The Apache Software Foundation.
 3   
  * 
 4   
  * Licensed under the Apache License, Version 2.0 (the "License");
 5   
  * you may not use this file except in compliance with the License.
 6   
  * You may obtain a copy of the License at
 7   
  * 
 8   
  *      http://www.apache.org/licenses/LICENSE-2.0
 9   
  * 
 10   
  * Unless required by applicable law or agreed to in writing, software
 11   
  * distributed under the License is distributed on an "AS IS" BASIS,
 12   
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13   
  * See the License for the specific language governing permissions and
 14   
  * limitations under the License.
 15   
  */
 16   
 
 17   
 package org.apache.geronimo.ews.ws4j2ee.utils;
 18   
 
 19   
 import java.io.File;
 20   
 import java.io.IOException;
 21   
 import java.io.InputStream;
 22   
 import java.lang.reflect.Method;
 23   
 import java.util.ArrayList;
 24   
 import java.util.StringTokenizer;
 25   
 
 26   
 import javax.xml.namespace.QName;
 27   
 import javax.xml.parsers.DocumentBuilder;
 28   
 import javax.xml.parsers.DocumentBuilderFactory;
 29   
 
 30   
 import org.apache.axis.AxisFault;
 31   
 import org.apache.axis.utils.ClassUtils;
 32   
 import org.apache.axis.utils.JavaUtils;
 33   
 import org.apache.geronimo.ews.ws4j2ee.context.J2EEWebServiceContext;
 34   
 import org.apache.geronimo.ews.ws4j2ee.toWs.GenerationFault;
 35   
 import org.w3c.dom.Document;
 36   
 import org.w3c.dom.Node;
 37   
 import org.w3c.dom.NodeList;
 38   
 import org.w3c.dom.Text;
 39   
 import org.xml.sax.EntityResolver;
 40   
 import org.xml.sax.InputSource;
 41   
 import org.xml.sax.SAXException;
 42   
 
 43   
 /**
 44   
  * This class was taken from the axis XMLUtils. It should be properly adopted if to be used permanantly
 45   
  */
 46   
 public class Utils {
 47   
 //    protected static Log log =
 48   
 //        LogFactory.getLog(XMLUtils.class.getName());
 49   
         
 50   
     public static final String charEncoding = "ISO-8859-1";
 51   
     private static final String saxParserFactoryProperty =
 52   
             "javax.xml.parsers.SAXParserFactory";
 53   
 
 54   
     private static DocumentBuilderFactory dbf = getDOMFactory();
 55   
 
 56  31
     public static String getClassNameFromQuallifiedName(String qualifiedName) {
 57  31
         int index = qualifiedName.lastIndexOf('.');
 58  31
         if (index > 0)
 59  31
             qualifiedName = qualifiedName.substring(index + 1);
 60  31
         return qualifiedName;
 61   
     }
 62   
 
 63  31
     public static String getPackageNameFromQuallifiedName(String qualifiedName) {
 64  31
         int index = qualifiedName.lastIndexOf('.');
 65  31
         if (index > 0)
 66  31
             return qualifiedName.substring(0, index);
 67   
         else
 68  0
             return "";
 69   
     }
 70   
 
 71  8
     public static String getAbsolutePath(String path, String confFileLocation) throws GenerationFault {
 72  8
         if (path != null) {
 73  8
             if (path.indexOf(":/") > -1 || path.indexOf(":\\") > -1 || path.startsWith("/"))
 74  0
                 return path;
 75  8
             return confFileLocation + "/" + path;
 76   
         } else {
 77  0
             throw new GenerationFault("the path can not be null");
 78   
         }
 79   
     }
 80   
 
 81  41
     public static String firstCharacterToLowerCase(String name) {
 82  41
         char[] charName = name.toCharArray();
 83  41
         if (charName.length > 0)
 84  41
             charName[0] = Character.toLowerCase(charName[0]);
 85  41
         return new String(charName);
 86   
     }
 87   
 
 88  0
     public static String firstCharacterToUpperCase(String name) {
 89  0
         char[] charName = name.toCharArray();
 90  0
         if (charName.length > 0)
 91  0
             charName[0] = Character.toUpperCase(charName[0]);
 92  0
         return new String(charName);
 93   
     }
 94   
 
 95  0
     public static String qName2JavaName(QName qname) {
 96  0
         return org.apache.axis.wsdl.toJava.Utils.makePackageName(qname.getNamespaceURI())
 97   
                 + "." + firstCharacterToUpperCase(JavaUtils.xmlNameToJava(qname.getLocalPart()));
 98   
     }
 99   
 
 100  0
     public static Method getJavaMethod(String className, String methodName) throws AxisFault {
 101  0
         String primKey = null;
 102  0
         Class sei;
 103  0
         try {
 104  0
             sei = ClassUtils.forName(className);
 105  0
             java.lang.reflect.Method callMethod = null;
 106  0
             Method[] methods = sei.getMethods();
 107  0
             for (int i = 0; i < methods.length; i++) {
 108  0
                 if (methods[i].getName().equals(methodName)) {
 109  0
                     callMethod = methods[i];
 110   
                 }
 111   
             }
 112  0
             if (callMethod == null)
 113  0
                 throw new org.apache.geronimo.ews.ws4j2ee.toWs.UnrecoverableGenerationFault("Method " + methodName + " not found in the class" + className);
 114  0
             return callMethod;
 115   
         } catch (ClassNotFoundException e) {
 116  0
             throw AxisFault.makeFault(e);
 117   
         }
 118   
     }
 119   
 
 120  0
     public static Object createParameter(Object obj) {
 121  0
         return obj;
 122   
     }
 123   
 
 124  0
     public static Object createParameter(int in) {
 125  0
         return new Integer(in);
 126   
     }
 127   
 
 128  0
     public static Object createParameter(long in) {
 129  0
         return new Long(in);
 130   
     }
 131   
 
 132  0
     public static Object createParameter(float in) {
 133  0
         return new Float(in);
 134   
     }
 135   
 
 136  0
     public static Object createParameter(byte in) {
 137  0
         return new Byte(in);
 138   
     }
 139   
 
 140  0
     public static Object createParameter(short in) {
 141  0
         return new Short(in);
 142   
     }
 143   
 
 144  0
     public static Object createParameter(boolean in) {
 145  0
         return new Boolean(in);
 146   
     }
 147   
 
 148  0
     public static Object createParameter(double in) {
 149  0
         return new Double(in);
 150   
     }
 151   
 
 152  0
     public static String getParameter(String type, String name) {
 153  0
         if ("int".equals(type)) {
 154  0
             return "new Integer(" + name + ")";
 155  0
         } else if ("float".equals(type)) {
 156  0
             return "new Float(" + name + ")";
 157  0
         } else if ("double".equals(type)) {
 158  0
             return "new Double(" + name + ")";
 159  0
         } else if ("short".equals(type)) {
 160  0
             return "new Short(" + name + ")";
 161  0
         } else if ("boolean".equals(type)) {
 162  0
             return "new Boolean(" + name + ")";
 163  0
         } else if ("byte".equals(type)) {
 164  0
             return "new Byte(" + name + ")";
 165  0
         } else if ("long".equals(type)) {
 166  0
             return "new Long(" + name + ")";
 167  0
         } else if ("char".equals(type)) {
 168  0
             return "new Character(" + name + ")";
 169   
         } else {
 170  0
             return name;
 171   
         }
 172   
     }
 173   
 
 174  0
     public static String getReturnCode(String type, String name) {
 175  0
         if ("java.lang.Integer".equals(type) || "int".equals(type)) {
 176  0
             return "((java.lang.Integer)" + name + ").intValue()";
 177  0
         } else if ("java.lang.Float".equals(type) || "float".equals(type)) {
 178  0
             return "((java.lang.Float)" + name + ").floatValue()";
 179  0
         } else if ("java.lang.Double".equals(type) || "double".equals(type)) {
 180  0
             return "((java.lang.Double)" + name + ").doubleValue()";
 181  0
         } else if ("java.lang.Short".equals(type) || "short".equals(type)) {
 182  0
             return "((java.lang.Short)" + name + ").shortValue()";
 183  0
         } else if ("java.lang.Boolean".equals(type) || "boolean".equals(type)) {
 184  0
             return "((java.lang.Boolean)" + name + ").booleanValue()";
 185  0
         } else if ("java.lang.Byte".equals(type) || "byte".equals(type)) {
 186  0
             return "((java.lang.Byte)" + name + ").byteValue()";
 187  0
         } else if ("java.lang.Long".equals(type) || "long".equals(type)) {
 188  0
             return "((java.lang.Long)" + name + ").longValue()";
 189  0
         } else if ("java.lang.Character".equals(type) || "char".equals(type)) {
 190  0
             return "((java.lang.Character)" + name + ").charValue()";
 191   
         } else {
 192  0
             return "(" + type + ")" + name;
 193   
         }
 194   
     }
 195   
 
 196  4
     public static String getRootDirOfFile(String file) {
 197  4
         int index = file.lastIndexOf('/');
 198  4
         if (index < 0)
 199  0
             index = file.lastIndexOf('\\');
 200  4
         if (index > -1) {
 201  4
             return file.substring(0, index);
 202   
         } else {
 203  0
             return file;
 204   
         }
 205   
     }
 206   
 
 207   
     /**
 208   
      * @param returnType
 209   
      * @return
 210   
      */
 211  0
     public static String jni2javaName(String returnType) {
 212  0
         if (returnType == null)
 213  0
             return null;
 214  0
         if (!returnType.startsWith("[")) {
 215  0
             return returnType;
 216   
         } else {
 217  0
             returnType = returnType.substring(1);
 218   
         }
 219  0
         String end = "[]";
 220  0
         while (returnType.startsWith("[")) {
 221  0
             end = end + "[]";
 222  0
             returnType = returnType.substring(1);
 223   
         }
 224  0
         if (returnType.startsWith("B")) {
 225  0
             returnType = "byte";
 226  0
         } else if (returnType.startsWith("I")) {
 227  0
             returnType = "int";
 228  0
         } else if (returnType.startsWith("D")) {
 229  0
             returnType = "double";
 230  0
         } else if (returnType.startsWith("J")) {
 231  0
             returnType = "long";
 232  0
         } else if (returnType.startsWith("Z")) {
 233  0
             returnType = "boolean";
 234  0
         } else if (returnType.startsWith("F")) {
 235  0
             returnType = "float";
 236  0
         } else if (returnType.startsWith("S")) {
 237  0
             returnType = "short";
 238  0
         } else if (returnType.startsWith("L")) {
 239  0
             int index = returnType.indexOf(";@");
 240  0
             returnType.substring(1, index);
 241   
         }
 242  0
         return returnType + end;
 243   
     }
 244   
 
 245  68
     public static String getElementValue(NodeList nodesin) {
 246  68
         if (nodesin == null || nodesin.getLength() < 1)
 247  0
             return null;
 248  68
         Node node = nodesin.item(0);
 249  68
         NodeList nodes = node.getChildNodes();
 250  68
         for (int i = 0; i < nodes.getLength(); i++) {
 251  68
             Node temp = nodes.item(i);
 252  68
             if (temp instanceof Text) {
 253  68
                 return ((Text) temp).getNodeValue();
 254   
             }
 255   
         }
 256  0
         return null;
 257   
     }
 258   
 
 259  0
     public static String javapkgToURI(String pkg) {
 260  0
         StringTokenizer tok = new StringTokenizer(pkg, ".");
 261  0
         ArrayList tokens = new ArrayList();
 262  0
         while (tok.hasMoreElements()) {
 263  0
             tokens.add(tok.nextToken());
 264   
         }
 265  0
         int size = tokens.size();
 266  0
         if (size > 0) {
 267  0
             StringBuffer uribuf = new StringBuffer();
 268  0
             uribuf.append("http://");
 269  0
             uribuf.append((String) tokens.get(size - 1));
 270  0
             for (int i = size - 2; i >= 0; i--) {
 271  0
                 uribuf.append(".");
 272  0
                 uribuf.append((String) tokens.get(i));
 273   
             }
 274  0
             return uribuf.toString();
 275   
         } else {
 276  0
             return pkg;
 277   
         }
 278   
     }
 279   
 
 280  29
     public static String getFileNamefromClass(J2EEWebServiceContext j2eewscontext, String qulifiedName) {
 281  29
         String outdir = j2eewscontext.getMiscInfo().getOutPutPath();
 282  29
         if (!outdir.endsWith("/"))
 283  9
             outdir = outdir + "/";
 284  29
         return outdir + qulifiedName.replace('.', '/') + ".java";
 285   
     }
 286   
 
 287  11
     public static void prepareTheDir(String fileName) {
 288  11
         File file = new File(fileName);
 289  11
         File parent = file.getParentFile();
 290  11
         parent.mkdirs();
 291   
     }
 292  7
     private static DocumentBuilderFactory getDOMFactory() {
 293  7
           DocumentBuilderFactory dbf;
 294  7
           try {
 295  7
               dbf = DocumentBuilderFactory.newInstance();
 296  7
               dbf.setNamespaceAware(true);
 297   
           } catch (Exception e) {
 298   
 //              log.error(Messages.getMessage("exception00"), e );
 299  0
               dbf = null;
 300   
           }
 301  7
           return (dbf);
 302   
       }
 303   
       
 304  19
     public static Document createDocument(InputStream in) throws GenerationFault {
 305  19
         try {
 306  19
             DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
 307  19
             dbf.setNamespaceAware(true);
 308  19
             dbf.setValidating(false);
 309  19
             dbf.setExpandEntityReferences(false);
 310  19
             DocumentBuilder db = dbf.newDocumentBuilder();
 311  19
             EntityResolver er = new EntityResolver() {
 312  0
                 public InputSource resolveEntity(String publicId,
 313   
                                                  String systemId)
 314   
                         throws SAXException, IOException {
 315  0
                     InputStream is = null;
 316  0
                     if ("http://java.sun.com/dtd/ejb-jar_2_0.dtd".equalsIgnoreCase(systemId)) {
 317  0
                         return getInputSource(Utils.class.getClassLoader().getResourceAsStream("ejb-jar_2_0.dtd"));
 318  0
                     } else if ("http://java.sun.com/dtd/web-app_2_3.dtd".equalsIgnoreCase(systemId))
 319  0
                         return getInputSource(Utils.class.getClassLoader().getResourceAsStream("web-app_2_3.dtd"));
 320  0
                     return null;
 321   
                 }
 322   
 
 323  0
                 private InputSource getInputSource(InputStream is) throws IOException {
 324  0
                     if (is == null)
 325  0
                         throw new IOException("error at the project set up can not find entity");
 326  0
                     return new InputSource(is);
 327   
                 }
 328   
             };
 329  19
             db.setEntityResolver(er);
 330  19
             return db.parse(in);
 331   
         } catch (Exception e) {
 332  0
             throw GenerationFault.createGenerationFault(e);
 333   
         }
 334   
     }
 335   
 
 336   
 
 337   
 }
 338   
 
 339